package com.onpositive.datamap.core;

public class RepositoryUtil {

	static IObjectResolver resolver;

	public static IObjectResolver getResolver() {
		return resolver;
	}

	public static void setResolver(IObjectResolver resolver) {
		RepositoryUtil.resolver = resolver;
	}

	public static String getThumbnailUrl(String objectU, int size) {

		IDataObject obj = getByName(objectU);
		if (obj == null) {
			return null;
		}

		return getThumbnailUrl(size, obj);

	}	

	public static String getThumbnailUrl(int size, IDataObject obj) {
		String url = null;
		String burl = null;
		IImageObject[] galleryImages = obj.getGalleryImages();
		if (galleryImages.length == 0) {
			return null;
		}
		for (IImageObject mq : galleryImages) {
			String url2 = mq.getUrl(size, 32);
			if (!url2.equals(mq.getUrl(45, 45))) {
				url = url2;
				break;
			} else if (burl == null && url2.length() > 0) {
				burl = url2;
			}
		}
		if (url == null) {
			url = burl;
		}
		return url;
	}

	public static IDataObject getByName(String objectU) {
		if (resolver==null){
			return null;
		}
		return resolver.resolve(objectU);
	}
}